package com.yanfan.zutai.controller;

import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.core.page.TableDataInfo;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.zutai.aop.SysInitData;
import com.yanfan.zutai.aop.SysInitUpdateData;
import com.yanfan.zutai.domain.BDeviceWarnConfig;
import com.yanfan.zutai.service.IBDeviceWarnConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 报警配置Controller
 *
 * @author ruoyi
 * @date 2022-06-01
 */
@RestController
@RequestMapping("/zutai/bDeviceWarnConfig")
public class BDeviceWarnConfigController extends BaseController {
    @Autowired
    private IBDeviceWarnConfigService bDeviceWarnConfigService;

    /**
     * 查询报警配置列表
     */
    @GetMapping("/list")
    //@SysQueryData
    public TableDataInfo list(BDeviceWarnConfig bDeviceWarnConfig) {
        startPage();
        List<BDeviceWarnConfig> list = bDeviceWarnConfigService.selectBDeviceWarnConfigList(bDeviceWarnConfig);
        return getDataTable(list);
    }

    /**
     * 导出报警配置列表
     */
    @Log(title = "报警配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BDeviceWarnConfig bDeviceWarnConfig) {
        List<BDeviceWarnConfig> list = bDeviceWarnConfigService.selectBDeviceWarnConfigList(bDeviceWarnConfig);
        ExcelUtil<BDeviceWarnConfig> util = new ExcelUtil<BDeviceWarnConfig>(BDeviceWarnConfig.class);
        util.exportExcel(response, list, "报警配置数据");
    }

    /**
     * 获取报警配置详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(bDeviceWarnConfigService.selectBDeviceWarnConfigById(id));
    }

    /**
     * 新增报警配置
     */
    @Log(title = "报警配置", businessType = BusinessType.INSERT)
    @PostMapping
    @SysInitData
    public AjaxResult add(@RequestBody BDeviceWarnConfig bDeviceWarnConfig) {
        return toAjax(bDeviceWarnConfigService.insertBDeviceWarnConfig(bDeviceWarnConfig));
    }

    /**
     * 修改报警配置
     */
    @Log(title = "报警配置", businessType = BusinessType.UPDATE)
    @PutMapping
    @SysInitUpdateData
    public AjaxResult edit(@RequestBody BDeviceWarnConfig bDeviceWarnConfig) {
        return toAjax(bDeviceWarnConfigService.updateBDeviceWarnConfig(bDeviceWarnConfig));
    }

    /**
     * 删除报警配置
     */
    @Log(title = "报警配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bDeviceWarnConfigService.deleteBDeviceWarnConfigByIds(ids));
    }
}
